home *** CD-ROM | disk | FTP | other *** search
- //--------------------------------------------------------------
- //
- // Mugs.prg - Mugs Sample Application
- //
- // Main procedure for the Mugs application. This file defines
- // two classes: MugApp and DataAction. MugApp contains methods
- // for opening all forms and dialogs. The DataAction class
- // contains data navigation and modifition methods that are
- // called from the toolbar and menu.
- //
- // Dependencies: < See SET PROCEDURE list at the top of the
- // MugApp constructor. >
- //
- // Visual dBASE Samples Group
- //
- // $Revision: 1.24 $
- //
- // Copyright (c) 1997, Borland International, Inc.
- // All rights reserved.
- //
- //---------------------------------------------------------------
-
- local app, sRunFolder
- private sAppFolder
- SET TALK OFF
- sRunFolder = SET("DIRECTORY")
- sAppFolder = SUBSTR( PROGRAM(0), 1, ;
- LEN( PROGRAM( 0 ) ) - ( LEN( PROGRAM() ) + 4 ) )
-
- sRunFolder := '"' + sRunFolder + '"'
- sAppFolder := '"' + sAppFolder + '"'
- SET DIRECTORY TO &sAppFolder.
-
- // If running as a compiled app, extract
- // MugsR.dll if not found on disk.
- if ( "runtime" $ LOWER( VERSION(0) ) )
- copyOutOfEXE("MugsR.dll")
- endif
-
- app = new MugApp( sRunFolder )
- return ( app.open() )
-
- function copyOutOfEXE( sFile )
- local bCopied
- bCopied = false
- if ( ( not FILE( sFile ) ) and FILE( sFile, true ) )
- COPY FILE ( sFile ) TO ( sFile )
- bCopied := true
- endif
- return ( bCopied )
-
- class MugApp( sRunFolder )
- SET PROCEDURE TO PROGRAM(0)
- SET PROCEDURE TO "mugs.mnu" ADDITIVE
- SET PROCEDURE TO "mugbars.prg" ADDITIVE
- SET PROCEDURE TO "about.wfm" ADDITIVE
- SET PROCEDURE TO "fileOpen.wfm" ADDITIVE
- SET PROCEDURE TO "customer.wfm" ADDITIVE
- SET PROCEDURE TO "inventory.wfm" ADDITIVE
- SET PROCEDURE TO "supplier.wfm" ADDITIVE
- SET PROCEDURE TO "invoice.wfm" ADDITIVE
- SET PROCEDURE TO "toolbar.wfm" ADDITIVE
- SET PROCEDURE TO "ichart.wfm" ADDITIVE
- SET PROCEDURE TO "invoiceOpen.wfm" ADDITIVE
- SET PROCEDURE TO "customerSelect.wfm" ADDITIVE
- SET PROCEDURE TO "finder.wfm" ADDITIVE
- SET PROCEDURE TO "ireport.wfm" ADDITIVE
- SET PROCEDURE TO "invoice.rep" ADDITIVE
-
- _app.framewin.app = this
- this.restoreSet = new RestoreSet( sRunFolder )
- this.dataAction = new DataAction( this )
- this.rootMenu = new MugsMenu( _app.framewin, "Root")
- this.toolbars = new MugBars( this )
-
- function open
- CLOSE FORMS
- SET DESIGN OFF
- shell( false, true )
- _app.speedbar := false
- _app.framewin.text := "Mugs"
- this.toolbars.create()
- this.toolbars.appbar.attach( _app.framewin )
- this.rootMenu.onInitMenu()
- return( class::OpenFileOpenDialog( this ) )
-
- function close
- local f
- PRIVATE sFolder
- sFolder = this.restoreSet.folder
- CLOSE FORMS
- SET DIRECTORY TO &sFolder.
- this.toolbars.appbar.detach( _app.framewin )
- if ( "runtime" $ LOWER( VERSION(0) ) )
- quit
- else
- with ( _app )
- framewin.app := null
- framewin.text := this.restoreSet.frameText
- speedbar := this.restoreSet.speedBar
- endwith
- _app.framewin.root.release()
- SET DESIGN ON
-
- // Use temp form to force a refresh of the menubar.
- f = new Form()
- f.top = -100
- f.open()
- f.release()
-
- shell( true, true )
- this.toolbars.release()
- with ( this )
- restoreSet := null
- dataAction := null
- rootMenu := null
- toolbars := null
- endwith
- SET PROCEDURE TO
- endif
- return
-
- function openFileOpenDialog
- local d
- d = new FileOpenForm()
- d.mdi = false
- d.app = this
- return ( d.readModal() )
-
- function openInvoiceOpenDialog( nCustomerID )
- local d, bFound
- bFound = false
- d = new InvoiceOpenForm()
- d.mdi = false
- d.app = this
- d.fillInvoiceList( nCustomerID )
-
- if ( d.iCount > 0 )
- bFound := true
- d.readModal()
- else
- MSGBOX( "No invoices found for customer number: " + ;
- LTRIM(STR(nCustomerID)), ;
- "Customer - " + LTRIM(STR(nCustomerID)), ;
- 0)
- endif
- return ( bFound )
-
- function openCustomerSelectDialog( nID )
- local d
- d = new CustomerSelectForm()
- d.selectID = nID
- d.mdi := false
- d.readModal()
- nID := d.selectID
- return ( nID )
-
-
- function openToolbarDialog
- local d
- d = new ToolbarForm()
- d.app = this
- d.mdi := false
- return ( d.readModal() )
-
- function openAboutDialog
- local d
- d = new AboutForm()
- d.app = this
- d.mdi := false
- return ( d.readModal() )
-
- function openFinderDialog( thisForm )
- local d
- d = new FinderForm()
- d.rowset := thisForm.rowset
- d.mdi := false
- return ( d.readModal() )
-
- function openDataForm( f )
- local m, bOpen
- m = new mugsMenu( f, "Root" )
- this.toolbars.databar.attach( f )
- bOpen = f.open()
- f.setFocus()
- return ( bOpen )
-
- function openCustomerForm
- local f, bOpen
- f = new CustomerForm()
- f.app = this
- bOpen = f.app.openDataForm( f )
- return ( bOpen )
-
- function openInvoiceForm( nInvoiceID )
- local f, bOpen
- f = new InvoiceForm()
- f.app = this
- f.visible := false
- bOpen = f.app.openDataForm( f )
- if ( PCOUNT() == 1 )
- f.rowset.applyLocate( '"Invoice ID" = ' + STR(nInvoiceID) )
- endif
- f.visible := true
- return ( bOpen )
-
- function openInventoryForm
- local f, bOpen
- f = new InventoryForm()
- f.app = this
- bOpen = f.app.openDataForm( f )
- return ( bOpen )
-
- function openSupplierForm
- local f, bOpen
- f = new SupplierForm()
- f.app = this
- bOpen = f.app.openDataForm( f )
- return (bOpen)
-
- function openSupplierFormAsDialog( nID )
- local f, bRead
- f = new SupplierForm()
- bFound = f.rowset.applyLocate('"Supplier ID" = ' + nID )
- f.app = this
- f.title.text := "<h3>" + f.rowset.fields["Company"].value + "</h3>"
- f.text := "Supplier " + nID
- f.rowset := null
- f.mdi := false
- f.width := 76
- with ( f.book1 )
- dataSource = "ARRAY {'Supplier'}"
- width := 74
- buttonOK.visible := true
- buttonCancel.visible := true
- endwith
- f.form_onSize(0, f.width, f.height)
- bRead = f.ReadModal()
- return ( bRead )
-
- function readIChart
- local f
- f = new IChartForm()
- f.mdi := false
- return ( f.readModal() )
-
- function renderInvoice
- local bOK, nInvoice, f, r
- bOK = false
- nInvoice = 0
- f = new IReportForm()
- f.mdi := false
- f.readModal()
- bOK := f.OK
- nInvoice := f.spinInvoice.value
- if ( bOK )
- r = new InvoiceReport()
- r.invoice1.rowset.filter := '"Invoice ID" = ' + nInvoice
- if ( r.invoice1.rowset.count() > 0 )
- r.render()
- else
- MSGBOX("Invoice ID " + nInvoice + " not found.", ;
- "Alert", 0 )
- endif
- endif
- return ( bOK )
-
- endclass
-
- class RestoreSet( sRunFolder )
- this.folder = sRunFolder
- this.speedBar = _app.speedBar
- this.frameText = _app.framewin.text
- endclass
-
- class MugBars( app )
- this.app = app
- this.flat = true
- this.large = false
- this.hints = true
-
- function create
- this.appBar = new MugAppbar( this.app )
- this.dataBar = new MugDatabar( this.app )
- return true
-
- function reset
- this.appBar.reset()
- this.dataBar.reset()
- return true
-
- function release
- this.appBar := null
- this.dataBar := null
- return true
-
- endclass
-
- class dataAction( app )
- this.app = app
-
- function goFirst( thisForm )
- local bFirst
- bFirst = false
- if ( class::rowActive( thisForm ) )
- bFirst := thisForm.rowset.first()
- endif
- this.refreshMenu( thisForm )
- return ( bFirst )
-
- function goPrev( thisForm )
- local bPrev
- bPrev = false
- if ( class::rowActive( thisForm ) )
- if ( not thisForm.rowset.atFirst() )
- bPrev := thisForm.rowset.next( -1 )
- if ( not bPrev )
- thisForm.rowset.next()
- endif
- endif
- endif
- this.refreshMenu( thisForm )
- return ( bPrev )
-
- function goNext( thisForm )
- local bNext
- bNext = false
- if ( class::rowActive( thisForm ) )
- if ( not thisForm.rowset.atLast() )
- bNext := thisForm.rowset.next()
- if ( not bNext )
- thisForm.rowset.next(-1)
- endif
- endif
- endif
- this.refreshMenu( thisForm )
- return ( bNext )
-
- function goLast( thisForm )
- local bLast
- bLast = false
- if ( class::rowActive( thisForm ) )
- bLast := thisForm.rowset.last()
- endif
- this.refreshMenu( thisForm )
- return ( bLast )
-
- function locateRow( thisForm )
- local bFind
- bFind = false
- if ( class::rowActive (thisForm ) )
- bFind := thisForm.app.openFinderDialog( thisForm )
- endif
- return ( bFind )
-
- function appendRow( thisForm )
- local bAppend
- bAppend = false
- if ( class::rowActive( thisForm ) )
- try
- bAppend := thisForm.rowset.beginAppend()
- catch ( Exception e )
- MSGBOX("Unable to add a new row.","Alert",48)
- bAppend := false
- thisForm.rowset.abandon()
- endtry
- endif
- this.refreshMenu( thisForm )
- return ( bAppend )
-
- function deleteRow( thisForm )
- local bDelete
- bDelete = false
- if ( class::rowActive( thisForm ) )
- if ( MSGBOX("You are about to delete the current row." ;
- + CHR(13) ;
- + "Click Yes to delete the current row.", ;
- "Confirm", ;
- 4) == 6 )
- try
- bDelete := thisForm.rowset.delete()
- catch ( Exception e )
- MSGBOX("Unable to delete current row.","Alert",48)
- bDelete := false
- endtry
- this.goPrev( thisForm )
- endif
- endif
- this.refreshMenu( thisForm )
- return ( bDelete )
-
- function saveRow( thisForm )
- local bSave
- bSave = false
- if ( class::rowActive( thisForm ) )
- bSave := thisForm.rowset.save()
- endif
- return ( bSave )
-
-
- function refreshRow( thisForm )
- local bRefresh
- bRefresh = false
- if ( class::rowActive( thisForm ) )
- bRefresh := thisForm.rowset.refreshControls()
- endif
- return ( bRefresh )
-
-
- function abandonRow( thisForm )
- local bAbandon
- bAbandon = false
- if ( class::rowActive( thisForm ) )
- bAbandon := thisForm.rowset.abandon()
- endif
- this.refreshMenu( thisForm )
- return ( bAbandon )
-
- function rowActive( thisForm )
- local bActive
- bActive = true
- if ( thisForm.rowset == null ) OR ;
- ( NOT thisForm.rowset.parent.active )
- bActive := false
- endif
- return ( bActive )
-
- function refreshMenu( thisForm )
- local bAtFirst, bAtLast
- bAtFirst = thisForm.rowset.atFirst()
- bAtLast = thisForm.rowset.atLast()
-
- with ( thisForm.root.menuTable )
- menuFirst.enabled := ( not bAtFirst )
- menuPrev.enabled := ( not bAtFirst )
- menuNext.enabled := ( not bAtLast )
- menuLast.enabled := ( not bAtLast )
- endwith
- return ( ( not bAtFirst ) and ( not bAtLast ) )
-
- endclass
-
-